package com.kikcn;

import com.kikcn.jpa.entity.Role;
import com.kikcn.jpa.entity.User;
import com.kikcn.jpa.repo.RoleRepository;
import com.kikcn.jpa.repo.UserRepository;
import com.kikcn.mvc.MyUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import javax.annotation.PostConstruct;
import java.util.Arrays;
import java.util.Collections;

@SpringBootApplication
@ComponentScan(basePackages = {"com.kikcn.jpa,com.kikcn.mvc"})
public class SpringBootStudyApplication {

    @Autowired
    private UserRepository userRepo;
    @Autowired
    private RoleRepository roleRepo;

    @Bean
    public PasswordEncoder getPasswordEncoder(){
        return   NoOpPasswordEncoder.getInstance();
    }

    /*@PostConstruct
    public void init() {
        Role adminRole = new Role("admin");
        Role userRole = new Role("user");
        roleRepo.save(Arrays.asList(adminRole, userRole));

        User user = new User();
        user.setEmail("admin@kikcn.com");
        user.setPassword("admin");
        user.setRoles(Collections.singleton(adminRole));

        User user2=new User();
        user2.setEmail("user1@kikcn.com");
        user2.setPassword("user1");
        user2.setRoles(Collections.singleton(userRole));
        userRepo.save(Arrays.asList(user, user2));
    }*/
    public static void main(String[] args) {
        SpringApplication.run(SpringBootStudyApplication.class, args);
    }

}